﻿Imports System.Data.SqlClient
Imports System.Web.UI.HtmlControls
Imports System.Web.UI.WebControls
Imports System.Web.UI.WebControls.WebParts
Partial Class Tools_ChangePassword
    Inherits System.Web.UI.Page
    Public strConnection As String = ConfigurationManager.ConnectionStrings("DatabaseConnectionString").ConnectionString.ToString

    'Protected Sub Page_Init(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Init

    '    Dim obj As New Authorization
    '    Dim url As String = Request.AppRelativeCurrentExecutionFilePath

    '    Dim id As String = obj.GetMenuID(url)
    '    Dim is_Authorized As Boolean = obj.CheckAuthorization(id)

    '    If is_Authorized = True Then
    '        'User Authorized to See that page .. Continue
    '    Else
    '        'User is not Authorized 
    '        Response.Redirect("~/UnAuthorized.aspx")
    '    End If


    'End Sub

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        If Not IsPostBack Then

            rtbOldPassword.Focus()

            rtbOldPassword.Attributes.Add("onKeyPress", "doClick('" + ibtnSubmit.ClientID + "',event)")
            rtbNewPass.Attributes.Add("onKeyPress", "doClick('" + ibtnSubmit.ClientID + "',event)")
            rtbConfirmPass.Attributes.Add("onKeyPress", "doClick('" + ibtnSubmit.ClientID + "',event)")

            If Session("UserInfo") Is Nothing Then
                Response.Redirect("~/login.aspx")
            Else
                Dim SESCLASS As New SessionClass
                SESCLASS = Session("UserInfo")
                rtbuserName.Text = SESCLASS.getUserName

            End If


            Dim _lblPageTitle As Label
            _lblPageTitle = Me.Master.FindControl("lblPageTitle")
            _lblPageTitle.Text = GetLocalResourceObject("PageTitle")


        End If

    End Sub

    Protected Sub GetPassword(ByVal sender As Object, ByVal e As System.EventArgs) Handles rtbOldPassword.TextChanged

        Dim SESCLASS As New SessionClass
        SESCLASS = Session("UserInfo")
        Dim ID As String = SESCLASS.getUserID

        If Not String.IsNullOrEmpty(rtbOldPassword.Text) Then
            Dim con As New SqlConnection(strConnection)
            con.Open()
            Dim cmd As New SqlCommand("select * from UserTable where Password = @Pass and id = @ID ", con)
            cmd.Parameters.AddWithValue("@Pass", rtbOldPassword.Text)
            cmd.Parameters.AddWithValue("@ID", ID)
            Dim dr As SqlDataReader = cmd.ExecuteReader()
            If dr.HasRows Then
                rtbOldPassword.BackColor = Drawing.Color.FromArgb(255, 154, 205, 50)
                rtbOldPassword.CssClass = "Right"
                ibtnSubmit.Enabled = True
                checkpassword.Visible = True
                imgstatus.ImageUrl = "~/Design/images/Right.gif"

                lblStatus.Text = "Correct"

            Else
                rtbOldPassword.BackColor = Drawing.Color.FromArgb(255, 250, 128, 114)
                rtbOldPassword.CssClass = "Wrong"
                ibtnSubmit.Enabled = False
                checkpassword.Visible = True
                imgstatus.ImageUrl = "~/Design/images/Wrong.png"


                lblStatus.Text = "Your Password is incorrect !"
            End If
        Else
            rtbOldPassword.BackColor = Drawing.Color.White
            rtbOldPassword.CssClass = "inputPass"
            ibtnSubmit.Enabled = True
            checkpassword.Visible = False
        End If
    End Sub





    Protected Sub SaveInfo(ByVal sender As Object, ByVal e As System.EventArgs) Handles ibtnSubmit.Click

        Dim SESCLASS As New SessionClass
        SESCLASS = Session("UserInfo")
        Dim ID As String = SESCLASS.getUserID

        Dim Users As New UserSP
        Dim UsersDS As New Data.DataSet
        UsersDS = Users.QueryDatabase(DBParentStoredProcedureClass.SqlQueryType.FillDataset, "ChangeUserPassword", ID, rtbuserName.Text, , rtbConfirmPass.Text, , )
        Response.Redirect("../Default.aspx")
    End Sub

    Protected Sub Page_PreInit(sender As Object, e As System.EventArgs) Handles Me.PreInit
        Me.Theme = GetGlobalResourceObject("SystemResource", "Theme")
    End Sub

End Class
